package cn.edu.swu.infosystem_1;

import java.util.Scanner;
/**
 *  学校信息管理系统
 *  可以查看现有的学生信息、课程信息，并对学生信息进行修改
 */
public class Main {

    public static void main(String[] args) {

        // 创建对象（学生）
        Student student1 = new Student("1","Miyabi","female",23);
        Student student2 = new Student("2","Yukari","female",17);
        Student student3 = new Student("3","Gerson","male",99);
        // 为方便管理使用数组存储信息
        Student students[] = {student1,student2,student3};

        // 创建对象（课程）
        Course course1 = new Course("1","Java","Sheng Wu");
        Course course2 = new Course("2","Data Structure","Guobin·DateStreetic·He");
        Course course3 = new Course("3","Probability Theory","Long·Assemfield·Liu");
        // 为方便管理使用数组存储信息
        Course courses[] = {course1,course2,course3};

        System.out.println("==========示例修改==========");

        // 使用setter方法修改学生的年龄
        System.out.println("学生"+student2.getName()+"的当前年龄："+student2.getAge());
        student2.setAge(18);
        System.out.println("修改后学生"+student2.getName()+"的当前年龄："+student2.getAge());

        System.out.println("学生"+student3.getName()+"的当前年龄："+student3.getAge());
        student3.setAge(17);
        System.out.println("修改后学生"+student3.getName()+"的当前年龄："+student3.getAge());

        // 使用setter方法修改课程的任课教师
        System.out.println("课程"+course3.getCourseName()+"的当前任课教师："+course3.getTeacher());
        course3.setTeacher("Long·Assemfield·Zhang");
        System.out.println("修改后课程"+course3.getCourseName()+"的当前任课教授："+course3.getTeacher());

        // 自主修改信息

        // 是否修改判定
        Scanner sc = new Scanner(System.in);
        System.out.println("\n是否要修改学生或课程信息？(y/n)");
        String changeChoice = sc.nextLine();
        while (changeChoice.equalsIgnoreCase("y")){

            // 修改类型判定
            System.out.println("请选择要修改的类型：1-学生 2-课程");
            int typeChoice = Integer.parseInt(sc.nextLine());
            if (typeChoice == 1){

                // 修改学生判断
                System.out.println("请选择要修改的学生编号(1-"+students.length+"):");
                // 展示学生信息
                for (int i = 0; i < students.length; i++) {
                    students[i].showInfo();
                }
                int indexChoice = Integer.parseInt(sc.nextLine());
                if (indexChoice>=1 && indexChoice <=students.length){

                    // 修改属性类型判定
                    System.out.println("请选择要修改的属性: 1-姓名 2-性别 3-年龄");
                    int attributeChoice = Integer.parseInt(sc.nextLine());
                    switch (attributeChoice){
                        case 1:
                            System.out.println("请输入新的姓名:");
                            students[indexChoice - 1].setName(sc.nextLine());
                            break;
                        case 2:
                            System.out.println("请输入新的性别:");
                            students[indexChoice - 1].setGender(sc.nextLine());
                            break;
                        case 3:
                            System.out.println("请输入新的年龄:");
                            students[indexChoice - 1].setAge(Integer.parseInt(sc.nextLine()));
                            break;
                        default:
                            System.out.println("输入无效");
                    }
                }else {
                    System.out.println("无效学生编号!");
                }
            }else if (typeChoice == 2){
                // 修改课程判定
                System.out.println("请选择要修改的课程编号(1-"+courses.length+"):");
                // 展示课程信息
                for (int i = 0; i < courses.length; i++) {
                    courses[i].showInfo();
                }
                int indexChoice = Integer.parseInt(sc.nextLine());
                if (indexChoice >=1 & indexChoice <= courses.length){

                    // 修改属性类型判定
                    System.out.println("请选择要修改的属性: 1-课程名 2-任课老师");
                    int attribute = Integer.parseInt(sc.nextLine());

                    switch (attribute){
                        case 1:
                            System.out.println("请输入新的课程名");
                            courses[indexChoice - 1].setCourseName(sc.nextLine());
                            break;
                        case 2 :
                            System.out.println("请输入新的任课教师名");
                            courses[indexChoice - 1].setTeacher(sc.nextLine());
                            break;
                        default:
                            System.out.println("输入无效");

                    }
                }else {
                    System.out.println("无效的课程编号！");
                }

            }else {
                System.out.println("无效的选择！");
            }

            System.out.println("\n是否要修改学生或课程信息？(y/n)");
            changeChoice = sc.nextLine();
        }



        System.out.println("===========Student Information===========");
        student1.showInfo();
        student2.showInfo();
        student3.showInfo();

        System.out.println("===========Course Information============");
        course1.showInfo();
        course2.showInfo();
        course3.showInfo();
    }
}
